package com.chat.common.chat.dao;

import com.chat.common.chat.domain.entity.RoomFriend;
import com.chat.common.user.domain.enums.NormalOrNoEnum;
import com.chat.common.chat.mapper.RoomFriendMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 单聊房间表 服务实现类
 * </p>
 *
 * @author <a href="https://www.linxin.cc">lin</a>
 * @since 2024-09-22
 */
@Service
public class RoomFriendDao extends ServiceImpl<RoomFriendMapper, RoomFriend>{

    public RoomFriend getByKey(String key) {
        return lambdaQuery().eq(RoomFriend::getRoomKey, key)
                .select(RoomFriend::getId, RoomFriend::getStatus)
                .one();
    }

    public void restoreRoom(Long id) {
        lambdaUpdate().eq(RoomFriend::getId,id)
                .set(RoomFriend::getStatus, NormalOrNoEnum.NORMAL.getStatus())
                .update();
    }

    public void disableFriendRoom(String roomKey) {
        lambdaUpdate().eq(RoomFriend::getRoomKey, roomKey)
                .set(RoomFriend::getStatus, NormalOrNoEnum.NOT_NORMAL.getStatus())
                .update();
    }

    public RoomFriend getRoomById(Long roomId) {
        return lambdaQuery().eq(RoomFriend::getRoomId, roomId)
                .one();
    }

    public List<RoomFriend> listByRoomIds(List<Long> roomIds) {
        return lambdaQuery().in(RoomFriend::getRoomId, roomIds).list();
    }
}
